package com.gm.lib.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

import com.gm.lib.net.RequestConfig;

public class UserInfoDB {
    public static String userid = null;
    public static String url = RequestConfig.DEFAULT_URL+"/energyBar";


    public static void saveUserInfo(String phone, String pw, Context con) {
        SharedPreferences sp = con.getSharedPreferences("phones",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("phone", phone);
        editor.commit();
    }

    public static void saveFirstLoginKey(Context con, String key) {
        SharedPreferences sp = con.getSharedPreferences("firstLoginInfo", Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("key", key);
        editor.commit();
    }

    public static String getFirstLoginkey(Context con) {
        SharedPreferences sp = con.getSharedPreferences("firstLoginInfo", Context.MODE_PRIVATE);
        return sp.getString("key", null);

    }

    public static void setShare(Context con, String fileName, String key, String value) {
        SharedPreferences sp = con.getSharedPreferences(fileName,
                Context.MODE_PRIVATE);


    }

    public static void saveUserInfo(String phone, Context con) {
        SharedPreferences sp = con.getSharedPreferences("phones",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("phone", phone);
        editor.commit();
    }

    public static String getUserInfo(Context con) {
        SharedPreferences sp = con.getSharedPreferences("phones",
                Context.MODE_PRIVATE);
        return sp.getString("phone", "");
    }

    public static String getPW(Context con) {
        SharedPreferences sp = con.getSharedPreferences("userinfo",
                Context.MODE_PRIVATE);
        return sp.getString("pw", null);
    }


    public static String getValueByKey(Context con, String key) {
        SharedPreferences sp = con.getSharedPreferences("userinfoid",
                Context.MODE_PRIVATE);
        String postedStr = sp.getString(key, null);
        return postedStr;
    }

    public static void save(Context con, String key, String value) {
        SharedPreferences sp = con.getSharedPreferences("userinfoid",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static void ClearData(Context con) {
        SharedPreferences sp = con.getSharedPreferences("userinfoid",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
//        editor.putString("posted", null);
        editor.clear();
        editor.commit();
    }


    public static void setcaridandcar(Context context, String carid, String car) {

        SharedPreferences sp = context.getSharedPreferences("Car",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("carid", carid);
        editor.putString("car", car);
        editor.commit();
        Log.e("存储成功", carid + car);
    }


    public static String[] getcaridandcar(Context con) {
        String[] strings = new String[2];
        try {
            SharedPreferences sp = con.getSharedPreferences("Car",
                    Context.MODE_PRIVATE);

            strings[0] = sp.getString("carid", "");
            strings[1] = sp.getString("car", "还没有添加车辆");

            Log.e("取出", strings[0] + strings[1]);
        } catch (NullPointerException e) {

        }

        return strings;
    }

    /*public static void saveTitle(String title, Context con) {
        SharedPreferences sp = con.getSharedPreferences("title",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("title", title);
        editor.commit();
    }



    public static String getTitle(Context con) {
        SharedPreferences sp = con.getSharedPreferences("title",
                Context.MODE_PRIVATE);
        String strings=sp.getString("title", "");
        return strings;
    }*/
}
